package com.shiwaixiangcun.customer.module.intelligent

import android.graphics.Rect
import android.os.Bundle
import android.support.v7.widget.LinearLayoutManager
import android.support.v7.widget.RecyclerView
import android.view.View
import com.shiwaixiangcun.customer.R
import com.shiwaixiangcun.customer.adapter.AdapterSmartDevice
import com.shiwaixiangcun.customer.base.BaseActivity
import com.shiwaixiangcun.customer.entity.DeviceData
import com.shiwaixiangcun.customer.module.watch.BindWatchActivity
import com.shiwaixiangcun.customer.utils.DisplayUtil
import kotlinx.android.synthetic.main.activity_add_smart_device.*
import kotlinx.android.synthetic.main.top_bar_white.*


/**
 * 添加智能设备
 */
class AddSmartDeviceActivity : BaseActivity() {
    var mList: ArrayList<AdapterSmartDevice.DeviceSection>? = null

    var mAdapter: AdapterSmartDevice? = null

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_add_smart_device)
        initData()
        initView()
    }

    private fun initData() {

        mList = ArrayList()
        mAdapter = AdapterSmartDevice(mList)
        val camera = AdapterSmartDevice.DeviceSection(DeviceData(1, "与亲人视频通话，距离不再是问题", "智能摄像机", R.drawable.device_camera))
        val watch = AdapterSmartDevice.DeviceSection(DeviceData(2, "通话、定位、健康监测，一表搞定", "智能手表", R.drawable.device_watch))
        val tonometer = AdapterSmartDevice.DeviceSection(DeviceData(3, "检测数据实时同步云端，医生、家人同步查看", "智能血压计", R.drawable.device_tonometer))
        val glucometer = AdapterSmartDevice.DeviceSection(DeviceData(4, "检测数据实时同步云端，医生、家人同步查看", "智能血糖仪", R.drawable.device_glucometer))
        val header = AdapterSmartDevice.DeviceSection(true, "即将上线")
        mList?.add(watch)
        mList?.add(header)
        mList?.add(camera)


        mList?.add(tonometer)
        mList?.add(glucometer)


        mAdapter?.notifyDataSetChanged()
    }

    private fun initView() {
        tv_page_name.text = "添加智能设备"
        back_left.setOnClickListener { finish() }
        rv_device_type.layoutManager = LinearLayoutManager(this)
        rv_device_type.adapter = mAdapter
        rv_device_type.addItemDecoration(object : RecyclerView.ItemDecoration() {
            override fun getItemOffsets(outRect: Rect, view: View, parent: RecyclerView, state: RecyclerView.State?) {
                outRect.set(0, 0, 0, DisplayUtil.dip2px(mContext, 10f))
            }
        })

        mAdapter?.setOnItemClickListener { adapter, _, position ->
            //            val bundle = Bundle()
//            bundle.putString("id", "VIEW-1033897-RKWVK")

            val item = adapter.getItem(position) as AdapterSmartDevice.DeviceSection
            if (item.isHeader) {
                return@setOnItemClickListener
            } else {
                when (item.t.id) {
                    2 -> readyGo(BindWatchActivity::class.java)
//                    1 -> readyGo(AddSmartCameraActivity::class.java)
                    else -> {
                        showToastShort("敬请期待")
                    }
                }
            }
        }
    }
}
